﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using LinqObj;

/// <summary>
/// Summary description for ServiceListGenerator
/// </summary>

namespace ToolBoxPro
{
    public class ServiceListBuilder
    {
        public ServiceListBuilder()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private IDictionary<int, Service_Category> categoryList;
        /*
         * <table>
         * <thead> <th> </th> </thead>
         * <tbody>
         *  <tr>
         *      <td>
         *          <img src="campaign_status">
         *      </td>
         *      <td>
         *          <img src="allocated_status">
         *      </td>
         *      <td>
         *          <a>Property Address.......</a>
         *      </td>
         *      <td>
         *          create date
         *      </td>
         *  </tr>
         *  </tbody>
         *  <tfoot> <tr> </tr> </tfoot>
         * </table>
         */


        // Dictionary<int, string> dic = new Dictionary<int, string>();
        public ServiceListBuilder(IDictionary<int, Service_Category> categoryList)
        {
            this.categoryList = categoryList;
        }


        /*<h2 class="trigger"><a href="#">Web Design &amp; Development</a></h2>
        <div class="toggle_container">
        <div class="block">
        <table border="1" bordercolor="#0B0000" height="800" width="200">
        
        </table>
        </div>
        </div> */
        public Control BuildServiceList()
        {
            HtmlGenericControl container = new HtmlGenericControl("div");
            container.Attributes["style"] = "border:1px solid #333; margin-bottom:5px;";

            foreach (int key in categoryList.Keys)
            {
                Service_Category category = categoryList[key];
                HtmlGenericControl triggerHeader = new HtmlGenericControl("div");
                triggerHeader.Attributes["class"] = "technology";
                //triggerHeader.InnerHtml = "<a class='trigger' href='#'>" + category.service_category1 + "</a>";
                //triggerHeader.Attributes["style"] = "text-transform:uppercase;";
                triggerHeader.InnerText = category.service_category1;
                container.Controls.Add(triggerHeader);

                HtmlGenericControl div1 = new HtmlGenericControl("div");
                div1.Attributes["class"] = "thelanguage";
                container.Controls.Add(div1);

                HtmlGenericControl div2 = new HtmlGenericControl("div");
                div2.Attributes["class"] = "categorySelect droptbl";
                div1.Controls.Add(div2);

                //HtmlGenericControl triggerContainer = new HtmlGenericControl("div");
                //triggerContainer.Attributes["class"] = "toggle_container";
                //container.Controls.Add(triggerContainer);

                //HtmlGenericControl blockDiv = new HtmlGenericControl("div");
                //blockDiv.Attributes["class"] = "block";
                //triggerContainer.Controls.Add(blockDiv);

                HtmlGenericControl serviceTable = new HtmlGenericControl("table");
                serviceTable.Attributes["class"] = "service_table";
                serviceTable.Attributes["width"] = "100%";
                div2.Controls.Add(serviceTable);


                foreach (Service service in category.MyServices)
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();

                    if (category.service_category1.Trim().IndexOf(' ') != -1)
                    {
                        string[] str = category.service_category1.Trim().Split(' ');
                        for (int i = 0; i < str.Length; i++)
                        {
                            sb.Append(str[i]);
                        }
                    }
                    else
                    {
                        sb.Append(category.service_category1.Trim());
                    }

                    if (category.service_category1.Trim().ToLower() == "entry package"
                        || category.service_category1.Trim().ToLower() == "standard package"
                        || category.service_category1.Trim().ToLower() == "premium package"
                        || category.service_category1.Trim().ToLower() == "premium"
                        || category.service_category1.Trim().ToLower() == "intro package redhot deal"
                        )
                    {
                        serviceTable.Attributes["id"] = sb.ToString() + "_packagetype";
                    }
                    else
                    {
                        serviceTable.Attributes["id"] = sb.ToString();
                    }

                    HtmlGenericControl serviceEntry = new HtmlGenericControl("tr");
                    serviceEntry.Attributes["id"] = sb.ToString() + "_" + service.service_id.ToString();
                    serviceEntry.Attributes["class"] = "serviceEntry";
                    serviceTable.Controls.Add(serviceEntry);

                    HtmlGenericControl serviceName = new HtmlGenericControl("td");
                    serviceName.InnerHtml = String.Format("<a href='#'><p class='serviceInfo'>{0}</p></a>", service.service_name);
                    serviceEntry.Controls.Add(serviceName);

                    //HtmlGenericControl serviceDetail = new HtmlGenericControl("td");
                    //serviceDetail.InnerHtml = String.Format("<a href='#'><p class='serviceInfo'>{0}</p></a>", service.service_description);
                    //serviceEntry.Controls.Add(serviceDetail);

                    LiteralControl servicePrice = new LiteralControl(String.Format("<td><p class='price'>{0}</p></td>", "$" + service.service_charge.ToString("0.00")));
                    serviceEntry.Controls.Add(servicePrice);
                }
            }

            return container;
        }
    }

}